package org.softmed.rest.server.defaults.providers;

import java.util.List;

import org.softmed.persistence.PersistenceManager;
import org.softmed.persistence.PersistenceManagerProvider;
import org.softmed.rest.admin.aop.Aspect;
import org.softmed.rest.admin.aop.manager.AspectProvider;

import com.google.inject.Inject;
import com.google.inject.name.Named;

public class DefaultAspectProvider implements AspectProvider {

	@Inject
	@Named("AspectProviderName")
	static String providerName;

	@Override
	public List<Aspect> getAspects() throws Throwable {
		List<Aspect> apps;

		PersistenceManagerProvider manager = new PersistenceManagerProvider(
				providerName);
		PersistenceManager util = manager.getPersistenceManager();
		util.connect();
		try {
			apps = util.getObjects(Aspect.class);

			// Close ODB
			util.close();

			return apps;
		} catch (Exception e) {
			e.printStackTrace();
			try {
				util.close();
			} catch (Throwable t) {
				t.printStackTrace();
			}

		}

		return null;
	}

	public static String getProviderName() {
		return providerName;
	}

	public static void setProviderName(String providerName) {
		DefaultAspectProvider.providerName = providerName;
	}


}
